package org.dxy.trigger.http;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dxy.api.dto.RegisterEquipmentRequestDto;
import org.dxy.api.dto.UpdateEquipmentRequestDto;
import org.dxy.api.dto.response.R;
import org.dxy.infrastructure.persistent.po.query.EquipmentBasicViewPo;
import org.dxy.trigger.http.service.impl.EquipmentApplicationServiceImpl;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/equipment")
@RequiredArgsConstructor
public class EquipmentController {
    private final EquipmentApplicationServiceImpl equipmentApplicationService;
    
    /**
     * @description 注册新设备
     * @param dto 包含设备注册信息的请求DTO
     * @return 返回注册成功或失败的响应
     * @date 2025/7/20 20:01
     * @auther dxy
     */
    @PostMapping("/register")
    public R<Void> register(@Validated @RequestBody RegisterEquipmentRequestDto dto) {
        return equipmentApplicationService.register(dto);
    }

    /**
     * @description 分页查询设备列表（支持条件过滤）
     * @param page 分页参数（页码、每页大小等）
     * @param query 过滤条件（设备名称、类型、状态等）
     * @return 分页的设备列表响应
     * @date 2025/7/20 20:01
     * @auther dxy
     */
    @GetMapping("/list")
    public R<Page<EquipmentBasicViewPo>> list(
            @ParameterObject Page<EquipmentBasicViewPo> page,
            @ParameterObject EquipmentBasicViewPo query) {
        return equipmentApplicationService.list(page, query);
    }

    /**
     * @description 更新设备信息
     * @param id 设备ID
     * @param dto 包含更新信息的请求DTO
     * @return 返回更新成功或失败的响应
     * @date 2025/7/20 20:01
     * @auther dxy
     */
    @PutMapping("/{id}")
    public R<Void> update(@PathVariable Long id, @Validated @RequestBody UpdateEquipmentRequestDto dto) {
        return equipmentApplicationService.update(id, dto);
    }

    /**
     * @description 删除单个设备
     * @param id 设备ID
     * @return 返回删除成功或失败的响应
     * @date 2025/7/20 20:01
     * @auther dxy
     */
    @DeleteMapping("/{id}")
    public R<Void> delete(@PathVariable Long id) {
        return equipmentApplicationService.delete(id);
    }

    /**
     * @description 批量删除设备
     * @param ids 设备ID列表
     * @return 返回批量删除成功或失败的响应
     * @date 2025/7/20 20:01
     * @auther dxy
     */
    @DeleteMapping("/batch")
    public R<Void> batchDelete(@RequestBody List<Long> ids) {
        return equipmentApplicationService.batchDelete(ids);
    }
}

